package xio.ccf_201403;

import java.util.Scanner;

/**
 * 201403-3	命令行选项 100分
 * Created by Xio on 2017/11/13 0013.
 */
public class CmdOptions {
    public static void main(String[] args){
        int[] cmds = new int['z'+1];  //字符'a'-'z'中是命令的赋值为0-2，其中 0:不存在此命令 1:存在 2：存在且有参


        Scanner sc = new Scanner(System.in);

        //解析 命令 并赋值区分有参无参
        String cmdStr = sc.nextLine();
        char[] cmdStrc = cmdStr.toCharArray();
        for (int i = 0; i < cmdStrc.length; i++) {
            if (cmdStrc[i] == ':'){
                cmds[cmdStrc[i-1]] = 2;
                continue;
            }
            cmds[cmdStrc[i]] = 1;
        }

        int n = Integer.parseInt(sc.nextLine());
        for (int i = 1; i <= n; i++) {
            String[] testCmdArr = sc.nextLine().split(" ");
            if (testCmdArr.length <= 1) { //即测试命令为空或者只有"ls"
                System.out.println("Case "+i+":");
                continue;
            }
            parse(cmds, i, testCmdArr);

        }
    }

    private static void parse(int[] cmds, int i, String[] testCmdArr) {
        String[] result = new String['z'+1]; //存储输出结果，默认为null
        String testCmd="";
        for (int j = 1; j < testCmdArr.length; j++) {
            testCmd = testCmdArr[j];

            if (testCmd.startsWith("-") && testCmd.length()>1){
                char tmp = testCmd.charAt(1);
                if (cmds[tmp] == 1){  //无参命令可直接输出
                    result[tmp] = testCmd;
                }else if (cmds[tmp] == 2){  //有参命令需读入下一项，作为参数
                    j++;
                    if (j < testCmdArr.length) { //注意，有可能是最后一项，那样就没有参数，不输出
                        result[tmp] = testCmd +" "+testCmdArr[j];
                    }
                }else { // 不在命令列表里，停止继续读入
                    break;
                }
            }else {
                break;
            }
        }
        //输出
        StringBuilder sb = new StringBuilder();
        sb.append("Case ").append(i).append(": ");
        for (int k = 'a'; k < result.length; k++) {
            if (result[k] == null) continue;
            sb.append(result[k]).append(" ");
        }
        System.out.println(sb.toString());
    }
}
